package com.itheima.mapper;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {


    /**
     * 根据用户名和密码查询用户对象
     * @param username
     * @param password
     * @return
     */
    @Select("select * from tb_user where username = #{username} and password = #{password}")
    User select(@Param("username") String username,@Param("password")  String password);

    /**
     * 根据用户名查询用户对象
     * @param username
     * @return
     */
    @Select("select * from tb_user where username = #{username}")
    User selectByUsername(String username);

    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into tb_user values(null,#{username},#{password},#{manage})")
    void add(User user);

    /**
     * 查询所有用户
     * @return
     */
    @Select("select * from tb_user where manage !=1 ")
    List<User> selectAll();

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from tb_user where id = #{id}")
    void delete(@Param("id") int id);

    @Update("update tb_user set password = #{password} where id = #{id}")
    void change(@Param("password") String password,@Param("id") int id);

}
